package com.cxw.healthserver.response


/**
 * @createTime 2023/11/8 16:42
 * @author 崔兴旺
 * @description
 */
data class BaseResponse<T>(
    val code: String,
    val message: String,
    val data: T?,
) {

    companion object {
        fun <T : Any> success(body: T?): BaseResponse<T> {
            return BaseResponse(code = "200", message = "", data = body)
        }

        fun <T : Any> fail(errorMessage: String): BaseResponse<T> {
            return BaseResponse(code = "-1", message = errorMessage, data = null)
        }

        fun <T : Any> fail(errorMessage: String, code: String = "-1"): BaseResponse<T> {
            return BaseResponse(code = code, message = errorMessage, data = null)
        }
    }

    fun isSuccess(): Boolean {
        return code == "200"
    }
}
